package com.cch.cooperation.api.zone.listener;

import cn.hutool.core.util.ObjectUtil;
import com.cch.cooperation.api.zone.dto.ZonePostAddDTO;
import com.cch.cooperation.api.zone.event.ZoneRemindCompleteEvent;
import com.cch.cooperation.api.zone.service.ZonePostServiceImpl;
import com.cch.cooperation.dao.zone.enums.ZonePostEnum;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ZonePostListener {

    @Resource
    private ZonePostServiceImpl zonePostService;

    @EventListener
    public void onRemindComplete(ZoneRemindCompleteEvent e) {
        if(ObjectUtil.isNull(e.getZoneRemindItem())) {
            return;
        }
        ZonePostAddDTO req = new ZonePostAddDTO();
        req.setZoneId(e.getZoneRemindItem().getZoneId());
        req.setContent("【" + e.getZoneRemindItem().getContent() + "】完成。");
        req.setUserId(e.getZoneRemindItem().getCreateUserId());
        req.setSourceType(ZonePostEnum.SourceType.COMPLETE_RECORD.value);
        req.setSourceId(e.getZoneRemindItem().getId());
        zonePostService.add(req);
    }
}
